package com.one.dao;

import com.one.entity.Order;
import com.one.utils.DbConn;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class OrderDao {
    //增删改查的工具
    private QueryRunner runner = new QueryRunner(DbConn.getDataSource());

    /**
     * 查询所有订单记录
     * @return
     */
    public List<Order> selOrders(){
        List<Order> orders = new ArrayList<>();
        String sql = "select * from order order by order_id desc";
        try {
            orders = runner.query(sql, new BeanListHandler<>(Order.class));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return orders;
    }
}
